package com.qf.springmq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.0
 * @Author liujinchi
 * @Date 2023/3/3 13:37
 * @注释
 */
@Configuration
public class MQConfig {


    private static final String DEAD_LETTER_EXCHANGE_NAME = "DLX";
    private static final Object DEAD_LETTER_QUEUE_10S_ROUTINGKEY = "Dead";
    private static final String DELAY_QUEUE_A = "QueueB";

    @Bean("delayQueueB")
    public Queue delayQueueB(){
        Map<String,Object> args=new HashMap<>();
        args.put("x-dead-letter-exchange",DEAD_LETTER_EXCHANGE_NAME);
        args.put("x-dead-letter-routing-key",DEAD_LETTER_QUEUE_10S_ROUTINGKEY);
        args.put("x-message-ttl",10000);
        return QueueBuilder.durable(DELAY_QUEUE_A).withArguments(args).build();
    }
    @Bean("ExchangeB")
    public DirectExchange exchangeB(){

        return new DirectExchange("ExchangeB",true,false);
    }

    @Bean("ttlbinding")
    public Binding bindingTTl(){
        return BindingBuilder.bind(delayQueueB()).to(exchangeB()).with("routingkey-b");
    }

    @Bean("deadQueueB")
    public Queue deadQueueB(){
        return new Queue("deadQueueB",true,false,false);
    }
    @Bean("DLX")
    public DirectExchange DLX(){

        return new DirectExchange("DLX",true,false);
    }
    @Bean("deadbind")
    public Binding bindingDead(){
        return BindingBuilder.bind(deadQueueB()).to(DLX()).with("Dead");
    }
}
